package com.hxzy.shop.controller.market;

import com.github.pagehelper.PageInfo;
import com.hxzy.shop.dto.marketing.dto.PageRequest;
import com.hxzy.shop.dto.marketing.dto.req.AddImageReq;
import com.hxzy.shop.entity.DistributorImage;
import com.hxzy.shop.feign.marketing.MarketingFeign;
import com.hxzy.shop.vo.ApiException;
import com.hxzy.shop.vo.Result;
import com.hxzy.shop.vo.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ Author     ：dididi
 * @ Date       ：Created in 16:07 2023/8/10
 * @ Modified By：
 */
@RestController
@Api(tags = "分销推广")
@RequestMapping(value = "/distribute")
public class DistributionImageController {

    @Resource
    private MarketingFeign marketingFeign;

    @PostMapping(value = "/imageList")
    @ApiOperation(value = "分销推广图列表")
    public Result<PageInfo<DistributorImage>> imageList(@RequestBody PageRequest req){
        Result<PageInfo<DistributorImage>> result = this.marketingFeign.imageList(req);
        if (result.getCode() != ResultCode.SUCCESS.getCode()){
            throw new ApiException(500,result.getMsg());
        }
        return Result.success(result.getData());
    }

    @PostMapping(value = "/addImage")
    @ApiOperation(value = "新增分销推广图片")
    public Result<Object> addImage(@RequestBody AddImageReq req){
        Result<Object> result = this.marketingFeign.addImage(req);
        if (result.getCode() != ResultCode.SUCCESS.getCode()){
            throw new ApiException(500,result.getMsg());
        }
        return Result.success(result.getData());
    }
}
